package com.brozha.ans_sys.handler;

import com.brozha.ans_sys.exception.AnsSysException;
import com.brozha.ans_sys.utils.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author brozha
 * @since 2021/4/7
 */
@ControllerAdvice
public class GlobalExceptionHandler {


    @ExceptionHandler(AnsSysException.class)
    @ResponseBody
    public Result error(AnsSysException e){
        e.printStackTrace();
        return Result.fail(e.getCode(),e.getMsg());
    }


    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        return Result.fail(-1,"发生未知错误！！！");
    }



}
